package ast;

import java.util.ArrayList;

import compiler.OutputFormatter;

public class ArgList {
	
	private ArrayList<Variable> list;
	
	public ArgList(ArrayList<Variable> list) {
		this.list = list;
	}

	/**
	 * Gets the number of arguments
	 * @return the number of arguments
	 */
	public int getSize() {
		return list.size();
	}
	
	/**
	 * Returns the argument type of a given position
	 * @param argPos the position of the argument
	 * @return the type of the argument at the given position
	 */	
	public Type getArgType(int pos) {
		if(pos < list.size())
			return list.get(pos).getType();
		return null;
	}
	
	
	/**
	 * Generates the C source code of the current knot
	 * @param of The OutputFormatter where the code will be generated
	 */	
	public void genC(OutputFormatter of) {
		for(int i = 0; i < list.size(); i++) {
			Variable v = list.get(i);
			v.getType().genC(of);
			of.output(" " + v.getName());
			if(i != list.size() - 1)
				of.output(", ");
		}
	}

}
